package tts.model;
// Generated 25-nov-2013 10.10.24 by Hibernate Tools 4.0.0

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Users generated by hbm2java
 */
@Entity
@Table(name = "users", catalog = "test")
public class Users implements java.io.Serializable {

	//fields
	private static final long serialVersionUID = 4593239367968010486L;
	private int users_id;
	private String username;
	private String password;
	private boolean enabled;
	private List<Roles> rolesList = new ArrayList<Roles>();
	private List<Groups> groupsList = new ArrayList<Groups>();
	private UsrDetails usrDetails;

	//constructors
	public Users() {
	}

	public Users(String username, String password, boolean enabled) {
		this.username = username;
		this.password = password;
		this.enabled = enabled;
	}

	public Users(int id, String username, String password, boolean enabled,
			List<Roles> rolesList) {
		this.username = username;
		this.password = password;
		this.enabled = enabled;
		this.rolesList = rolesList;
	}

	public Users(int users_id, String username, String password,
			boolean enabled, List<Roles> rolesList,
			List<Groups> groupsList) {
		super();
		this.users_id = users_id;
		this.username = username;
		this.password = password;
		this.enabled = enabled;
		this.rolesList = rolesList;
		this.groupsList = groupsList;
	}

	//get & set	
	@Id
	@GeneratedValue
	@Column(name="users_id", unique = true, nullable = false, length = 10)
	public int getUsers_id() {
		return users_id;
	}
	public void setUsers_id(int users_id) {
		this.users_id = users_id;
	}

	@Column(name = "username", unique = true, nullable = false, length = 50)
	public String getUsername() {
		return this.username;
	}
	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password", nullable = false, length = 50)
	public String getPassword() {
		return this.password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "enabled", nullable = false, length = 1)
	public boolean isEnabled() {
		return this.enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

//	@OneToMany(fetch = FetchType.EAGER, mappedBy="users", cascade=javax.persistence.CascadeType.ALL)
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name = "users_roles", joinColumns = { @JoinColumn(name = "users_id") }, inverseJoinColumns = { @JoinColumn(name = "roles_id") })  
	public List<Roles> getRolesList() {
		return this.rolesList;
	}
	public void setRolesList(List<Roles> rolesList) {
		this.rolesList = rolesList;
	}

	@ManyToMany
	@JoinTable(name = "users_groups", joinColumns = { @JoinColumn(name = "users_id") }, inverseJoinColumns = { @JoinColumn(name = "groups_id") })  
	public List<Groups> getGroupsList() {
		return groupsList;
	}
	public void setGroupsList(List<Groups> groupsList) {
		this.groupsList = groupsList;
	}

	@OneToOne(mappedBy="users", cascade=javax.persistence.CascadeType.ALL, fetch=FetchType.EAGER)
	public UsrDetails getUsrDetails() {
		return usrDetails;
	}
	public void setUsrDetails(UsrDetails usrDetails) {
		this.usrDetails = usrDetails;
	}

	@Override
	public String toString() {
		return "Users [users_id=" + users_id + ", username=" + username
				+ ", password=" + password + ", enabled=" + enabled
				+ ", rolesList=" + rolesList + ", groupsList="
				+ groupsList + ", usrDetails=" + usrDetails + "]";
	}
}